<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2024/9/23
  Time: 9:48
  To change this template use File | Settings | File Templates.
--%>
<%--<% String id = request.getParameter("id"); %>--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %>
<html>
<head>
    <title>整表查询数据</title>
    <%!
        ResultSet  rs;//数据库查询结果集对象
    %>
    <%
        String dbName="jdbc";//数据库名称
        String userName="root";//数据库用户名
        String dbPassword="123456";//数据库密码
        String url="jdbc:mysql://192.168.13.11/"+dbName+"?user="+userName+"&password="+dbPassword;//数据库连接地址
        Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动
        Connection conn=DriverManager.getConnection(url);//获取数据库连接
        Statement satement=conn.createStatement();
        String sql="select * from student";//查询语句
        rs=satement.executeQuery(sql);//执行查询语句，并获取查询结果集对象
    %>
</head>
<body>
<form action="first.jsp" method="post">
    <table>
        <tr colspan="2" >查询条件</tr>
        <tr>
            <td>学号：</td>
            <td><input type="text" name="stupid" id="stupid"></td>
        </tr>
        <tr aria-rowspan="2"><input type="submit" value="提交"></tr>
    </table>
</form>
    <table border="1">
        <th colspan="4" style="text-size: x-large;alignment: center">学生信息表</th>
        <tr style="text-align: center">
            <th>学号</th>
            <th>姓名</th>
            <th>出生日期</th>
            <th>所在班级</th>
        </tr>
        <tr>
            <%while(rs.next()){//使用表达式显示结果集中对应的列数据%>
            <tr>
                <td><%=rs.getString("id")%></td>
                <td><%=rs.getString("student_name")%></td>
                <td><%=rs.getString("gender")%></td>
                <td><%=rs.getString("birthday")%></td>
    </tr>
        <%}%>
        <%--关闭数据库连接--%>
        <%
            rs.close();
            satement.close();
            conn.close();
        %>
        </tr>
    </table>
</body>
</html>
